package com.ctsi.organise.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.commons.util.id.UUIDGenerator;
import com.ctsi.commons.util.response.Page;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.organise.entity.PersonRY;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Map;

/**
 * @auth:wgf
 * @description :
 * @Date: 2019/3/20
 */
@Repository
public class PersonRyService {
    private static final Logger logger= LoggerFactory.getLogger(PersonRyService.class);
    @Autowired
    private MybatisGenericDao dao;
    /**
     * 添加荣誉
     */
    public int insertPersonRY(PersonRY personRY){
        if(UtilValidate.isEmpty(personRY.getId()))
            personRY.setId(UUIDGenerator.getId());
        logger.debug("insert {}",personRY);
       return dao.insert(personRY);
    }
    /**
     * 动态更新荣誉
     */
    public int updatePersonRyByPKSelective(PersonRY personRY){
        logger.debug("updateByPrimaryKeySelective {}",personRY);
        return dao.update(PersonRY.class.getName()+".updateByPrimaryKeySelective", personRY);
    }
    /**
     * 根据ID查询荣誉详情
     */
    public PersonRY findPersonRyById(String id){
        if(UtilValidate.isEmpty(id))
            return null;
        logger.debug("findById {}",id);
        return dao.get(PersonRY.class, id);
    }
    /**
     * 根据ID删除荣誉
     */
    public int deletePersonRyById(String id){
        if(UtilValidate.isNotEmpty(id)){
            return dao.delete(PersonRY.class.getName()+".delete", id);
        }
        return 0;
    }

    /**
     *  根据PersonID查询荣誉列表
     */
    public Page<PersonRY> queryListPersonRY(Map<String,Object> param , int start , int pageSize){
        logger.debug("selectMulitCondition {}",param);
        if(pageSize<0||pageSize>2000)
            pageSize=Page.DEFAULT_PAGE_SIZE;
        if(start!=-1)
            return dao.queryPage(PersonRY.class.getName()+".selectMulitCondition", param, start, pageSize);
        else{
            throw new RuntimeException("参数不正确 !!");
        }
    }
}
